package cn.edu.sicnu.cs.lgy.myapplication

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import kotlinx.android.synthetic.main.fragment_blank_list.*

class BlankFragmentList : Fragment() {
    val stuList = mutableListOf<Student>()
    lateinit var adapter: ArrayAdapter<Student>
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        stuList.add(Student("lgy",46))
        stuList.add(Student("fxk",41))
        stuList.add(Student("gaoyuexiang",47))
        context?.let {
            adapter = ArrayAdapter(it,android.R.layout.simple_list_item_1,stuList)
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_blank_list, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        listView.adapter = adapter

        listView.setOnItemClickListener { parent, view, position, id ->
            val stu = stuList.get(position)
            val transaction = parentFragmentManager.beginTransaction()
            transaction.setCustomAnimations(android.R.anim.slide_in_left,android.R.anim.fade_out,android.R.anim.fade_in,android.R.anim.slide_out_right)
            transaction.replace(R.id.fragmentContainerView,BlankFragment3.newInstance(stu))
            transaction.addToBackStack(null)
            transaction.commit()
        }
    }

}